﻿@using GoodMan.Infrastructure.Entities.Entity;
@{
    Layout = "~/Views/Shared/_Main.cshtml";
    int productId = ViewBag.productiId == null ? 0 : ViewBag.productiId;
    Product product = ViewBag.product == null ? new Product() : ViewBag.product;
    ViewBag.Title = product.ProductName;
    Policy Specialpolicy = ViewBag.policy;// == null ? new Policy() : ViewBag.policy;
    int areaCode = ViewBag.AreaCode == null ? 0 : ViewBag.AreaCode;
    int type = ViewBag.Type == null ? 0 : ViewBag.Type;
    ItemListBox<OrderDetail> orderDetails = ViewBag.saleRecord;
    ItemListBox<Appraise> appraiselist = ViewBag.appraiselist;
    DateTime hisDate = new DateTime(1970, 1, 1);
    double serverDate = (DateTime.Now - hisDate).TotalSeconds;
    bool IsUnderstock = ViewBag.IsUnderstock;
    int productRemain = ViewBag.ProductRemain;

    decimal discount = 10;
    discount = Math.Round(product.policy.Price / product.OriginalPrice * 10, 2);

    double price = (double)product.policy.Price;
    double originalPrice = (double)product.OriginalPrice;

    double savemoney = originalPrice - price;

    double totalmilseconds = (product.policy.ExpireDate - hisDate).TotalSeconds;
    
    double totalAppraise = ViewBag.totalAppraise == null ? 5.0d : ViewBag.totalAppraise;
    string Satisfaction = ViewBag.Satisfaction == null ? "100%" : ViewBag.Satisfaction;

    int IsViewAppriaseBtn = ViewBag.IsViewAppriaseBtn == null ? 0 : ViewBag.IsViewAppriaseBtn;

    int DelAuthenticate = ViewBag.DelAuthenticate == null ? 0 : ViewBag.DelAuthenticate;
    
    int islogin = 1;
    var loginUrl = "";
    if (!HttpContext.Current.User.Identity.IsAuthenticated)
    {
        islogin = 0;
        string tourl = System.Web.HttpContext.Current.Request.RawUrl;
        loginUrl = "/account/login?returnurl=" + System.Web.HttpContext.Current.Server.UrlEncode(tourl);
    }
    int userRole = ViewBag.userRole == null ? 1 : ViewBag.userRole;
     
}
@section head
{
      <script type="text/javascript">

          function submitform() {
              document.forms["buyproduct"].submit();
          }

          function changeNum() {
              // alert(id + price);
              var num = $("#buyCount").val();
              if (num == "" || num <= 0) {
                  $("#buyCount").val("1");
                   
                  alert("数量不能为空且必须大于等于1");
              }
              else if(num>@productRemain)
              {
                    $("#buyCount").val(@productRemain);
                    alert("库存不足,仅剩"+@productRemain+"件");
              }
              
          }

          function doAppraise()
          {
              var obj=$("#doAppraise");
              var classstr= obj.attr("class").toString();
              if(classstr=="Hide")
              {
                obj.removeClass("Hide");
                obj.addClass("View");
                obj.css("display","block");
              }
              else
              {
                obj.removeClass("View");
                obj.addClass("Hide");
                obj.css("display","none");
              }
          }

          function addcart()
                {
                 
                 $.post("/Shop/AddProductToCart",{ verNames: $("#verNames").val(),verValues: "",
　　                productid:$("#productid").val(),
　　                buycount:1}, function (response){
                   $("#cart").html(response.split('^')[0]);
                    $("#shoppingcartitem").html(response.split('^')[1]);
                });
                alert("亲，加入购物车成功。");
                //return false;
　　            
　　          }
      </script>
     

}
<div class="container">
    <ul class="breadcrumb">
        <li><a href="../home/index">首页</a> <span class="divider">></span></li>
        <li><a href="/shop/PrductArea?code=groupbuy">校园团购</a> <span class="divider">></span></li>
         <li>
        @{
            if (product.productCategory != null)
            {
                <span>@product.productCategory.CategoryName</span>
            }
            else
            {
                <span>默认分类</span>
            }
            }<span class="divider">></span></li>
        <li class="active">@product.ProductName</li>
    </ul>
    <!--//////////////////////////////////////////////////////////////////////////////////-->
    <div class="row">
        <div class="span12">
            <div class="offset-x">
            <form action="/shop/DirectPurchase" method="post" name="buyproduct" id="buyproduct" >
             <input type="hidden" id="productid" name="productid" value="@productId" />
             <input type="hidden" id="buyCount" name="buyCount" value="1" />
                <div class="row-fluid group-on-details">
                    <div class="group-on-title">
                        @product.ProductName
                    </div>
                    <div class="row-fluid">
                        <div class="span3 bg-group-details">
                            <div class="gl-1 row-fluid">
                                <div class="span5 group-price">
                                    &yen;<span>@price</span>
                                </div>
                                <div class="span7">
                                    <div>
                                        价值： <del>&yen;@originalPrice</del>
                                    </div>
                                    <div>
                                        折扣：@discount 折</div>
                                </div>
                            </div>
                            <div class="gl-2 text-center" style="height: 72px">
                                <div id="submitbtn">
                                @{
                                    var disable = "";
                                    if (userRole != 1 || product.SaleCount >= product.CapsPeople)
                                    {
                                        disable = "disabled=\"disabled\"";
                                    }
                                    if (islogin == 1)
                                    {
                                        <button type="button" onclick="submitform();return false;" id="topBtn" class="btn btn-warning" @disable ><span class="icon-ok icon-white"></span>&nbsp;立即抢购</button>
                                        <button type="button" class="btn" id="topcart" onclick="addcart();return false;" @disable><span class="icon-shopping-cart"></span>&nbsp;购物车</button>
                                    }
                                    else
                                    {
                                        <a id="topBtn" class="btn btn-warning" href="@loginUrl"><span class="icon-ok icon-white"></span>&nbsp;立即抢购</a>
                                        <button type="button" class="btn" id="topcart" onclick="addcart();return false;"><span class="icon-shopping-cart"></span>&nbsp;购物车</button>
                                    }
                                     
                                }
                                    </div>
                            </div>
                            <div class="gl-3 text-center">
                                <h4>
                                    <span class="red">@product.SaleCount</span> 人已经团购</h4>
                                <div>
                                    <span id="lefttime" name="lefttime" style="margin-bottom:10px;color:#666;font-size:15px;" value="@totalmilseconds">
                                    </span>
                                </div>
                            </div>
                            <!--如果支持-->
                            <div class="gl-4 row-fluid text-center">
                                <div class="span6">
                                    <span class="icon-refund-no"></span><a href="#"><small>不支持随时退款</small> </a>
                                </div>
                                <div class="span6">
                                    <span class="icon-due-no"></span><a href="#"><small>不支持过期退款</small> </a>
                                </div>
                            </div>
                        </div>
                        <div class="span8">
                            <!--封面大小:460x285-->
                            @{
                                if (product.Images!=null&&product.Images != "")
                                {
                                    var imgStr = product.Images.Split(';')[0];
                                <img  style="width:800px;height:285px" src="@imgStr" />
                                }
                                else
                                {
                                <img class="cover" src="" />
                                }
                            }
                             
                        </div>
                    </div>
                    <hr />
                </div>
                </form>
                <div class="clearfix">
                </div>
            </div>
            <br />
            <div class="row-fluid border-gray evaluate-result">
                <div class="padding-h-10">
                    <div class="span10">
                        会员评分：<span class="red">@totalAppraise</span><span class="">
                        @{
                            for (int j = 0; j < Math.Round(totalAppraise); j++)
                            {
                                     <img src="/content/img/star.png" />
                            }
                        }
                         
                        </span>，满意率<span class="red">@Satisfaction</span> ！
                    </div>
                    <div class="span2 text-right">
                        &nbsp;</div>
                </div>
            </div>
            
            <!--////////////////////////////////////////////////////////////////////////////-->
            <div class="tabbable border-gray">
                <ul class="nav nav-tabs">
                    <li class="active"><a href="#tab1" data-toggle="tab">团购描述</a></li>
                    <li><a href="#tab2" data-toggle="tab">会员评价</a></li>
                </ul>
                <div class="tab-content">
                    <div class="tab-pane active" id="tab1" style="overflow: hidden">
                        <!--/////////////////////////////////////////////////////////////////-->
                        @Html.Raw(product.Description)
                        <!--/////////////////////////////////////////////////////////////////-->
                    </div>
                    <div class="tab-pane" id="tab2" style="overflow:hidden">
                        <h4 class="border-bottom-gray red bg-bar">
                            &nbsp;&nbsp;总体评价</h4>
                        <div class="row-fluid text-center border-bottom-gray evaluate-box">
                            <div class="span4">
                            @{
                                <div>
                                    <strong class="text-large red">@totalAppraise</strong> 分</div>
                                @:<div>
                                for (int j = 0; j < Math.Round(totalAppraise); j++)
                                {
                                     <img src="/content/img/star.png" />
                                }
                                @:</div>
                            } 
                            </div>
                            <div class="span4">
                                <div class="border-hv-dot">
                                     
                                    <div>
                                        <span class="red">@Satisfaction</span> 的会员满意本次团购</div>
                                </div>
                            </div>
                            <div class="span4">
                                
                               @* @{
                                    if (IsViewAppriaseBtn == 1)
                                    {
                                        <a  href="javascript: doAppraise()" class="btn btn-danger" style="margin-left:50px;"><span class="icon-edit icon-white">
                                </span>&nbsp;我要评论</a>
                                    }
                                } *@
                            </div>
                        </div>
                       @* @{
                         if(IsViewAppriaseBtn==1)
                         {   
                             <div id="doAppraise" class="Hide" style="overflow:hidden;display:none">
                        <h4 class="border-bottom-gray red bg-bar">
                            &nbsp;&nbsp;我要评价</h4>
                            <div class="padding-h-10">
                                <form  action="/shop/Appraise" method="post">
                                <input type="hidden" value="@productId" name="pid" />
                               <div class="row-fluid">
                               <div>评分：<span><input type="radio" value="5" checked="checked" name="appraiseGrade"/>非常满意</span>
                               &nbsp;&nbsp;<span><input type="radio" value="4"  name="appraiseGrade"/>满意</span>
                               &nbsp;&nbsp;<span><input type="radio" value="2"  name="appraiseGrade"/>一般</span>
                               &nbsp;&nbsp;<span><input type="radio" value="1"  name="appraiseGrade"/>不满意</span>
                               &nbsp;&nbsp;<span><input type="radio" value="0"  name="appraiseGrade"/>非常不满意</span> 
                               </div>
                               <br />
                               <textarea style="width:99%" name="appraiseContent"></textarea>
                               <br />
                               <div class="text-center"><input type="submit" class="btn btn-danger" value="确定"/></div>
                                </div>
                                </form>
                            </div>
                            </div>
                           }
                            
                        }*@
                        <!--//////////////////////////////////////////////////////////////////////////////////-->
                        <h4 class="border-bottom-gray red bg-bar">
                            &nbsp;&nbsp;全部评价</h4>
                            @{
                                if (appraiselist != null && appraiselist.Data != null && appraiselist.Data.Any())
                                {
                                    foreach (var Item in appraiselist.Data)
                                    {
                                        string date = Item.AppraiseDate.ToString("yyyy-MM-dd HH:mm:ss");
                                           
                                            <div class="padding-h-10">
                                            <div class="row-fluid">
                                                <div class="span8 muted">
                                                    @Item.user.NickName &nbsp;&nbsp;&nbsp;@date &nbsp;&nbsp;&nbsp;
                                                    @{
                                                        if(DelAuthenticate==1)
                                                        {
                                                            <a href="/shop/DelAppraise?id=@Item.Id&type=0&productid=@productId" class="btn btn-danger btn-mini">删除</a>
                                                        }
                                                     }
                                                </div>
                                                <div class="span4 text-right">

                                                @{
                                        for (int i = 0; i < Item.AppraiseGrade; i++)
                                        {
                                                        <img src="/content/img/star.png" />
                                        }
                                                  }
                                                     
                                                </div>
                                            </div>
                                            <small>@Item.AppraiseContent
                                            </small>
                                        </div>
                                        <div class="line-dot">
                                        </div>
                                    }
                                }
                            }
                        
                        <!--分页-->
                        <div class="pagination text-right">
                            <a href="/shop/ProductAppraises?id=@productId" target="_blank">更多评价>></a>
                        </div>
                        <!--#分页-->
                    </div>
                </div>
            </div>
            <!--价格-->
            <div class="alert alert-error">
                <div class="pull-left">
                    <span class="important text-large">&yen;@price</span> <span class="">原价：&yen;@originalPrice</span>&nbsp;&nbsp;
                    <span class="">折扣：@discount 折</span>&nbsp;&nbsp; <span class="">节省：@savemoney 元</span>
                </div>
                <div class="pull-right">
                    @{
                         disable = "";
                        if (userRole != 1)
                        {
                            disable = "disabled=\"disabled\"";
                        }
                        if (islogin == 1)
                        {
                            <button id="bottomBtn" onclick="submitform()" class="btn btn-warning" @disable><span class="icon-ok icon-white"></span>&nbsp;立即抢购</button>
                            
                        }
                        else
                        {
                            <a id="bottomBtn" href="@loginUrl" class="btn btn-warning" ><span class="icon-ok icon-white"></span>&nbsp;立即抢购</a>
                        }
                                     
                    }
                     
                </div>
                <div class="clearfix">
                </div>
            </div>
            <!--#价格-->
        </div>
    </div>
</div>
@section tail{
    <script type="text/javascript">
        var serverTime = parseInt('@serverDate') * 1000;
        $(function () {

            var dateTime = new Date();

            var difference = dateTime.getTime() - serverTime;

            window.setInterval(function () {
                $("#lefttime").each(function () {
                    var obj = $(this);

                    var endTime = new Date(parseInt(obj.attr('value')) * 1000);
                    var nowTime = new Date();
                    var nMS = endTime.getTime() - nowTime.getTime() + difference;
                    var myD = Math.floor(nMS / (1000 * 60 * 60 * 24));
                    var myH = Math.floor(nMS / (1000 * 60 * 60)) % 24;
                    var myM = Math.floor(nMS / (1000 * 60)) % 60;
                    var myS = Math.floor(nMS / 1000) % 60;
                    var myMS = Math.floor(nMS / 100) % 10;
                    if (myD >= 0) {
                        var str = myD + "天" + myH + "小时" + myM + "分" + myS + "." + myMS + "秒";
                    } else {
                        var str = "团购已结束！";
                        $("#topBtn").css('display', 'none');
                        $("#bottomBtn").css('display', 'none');
                        $("#topcart").css('display', 'none');
                    }
                    obj.html(str);
                });
            }, 100);

             
        });
 
    </script>
}
